/**
 * 
 */
package com.jysz.webcore.ssh.service;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;

import com.jysz.webcore.ssh.orm.hibernate.HibernateDao;
import com.jysz.webcore.ssh.orm.hibernate.support.Page;

/**
 * service基类，主要用于对于一些纯CRUD，可以直接继承此抽象类，减少代码量
 * 
 * @author kacarich email:javaengine@outlook.com
 *
 * @param <T> 实体对象类型
 * @param <D> dao对象类型
 */
public abstract class EntityService<T, PK extends Serializable, D extends HibernateDao<T, PK>> {

	public abstract D getEntityDao();

	public T find(PK id) {
		return getEntityDao().find(id);
	}
	
	public T get(PK id) {
		return getEntityDao().get(id);
	}

	public List<T> findAll() {
		return getEntityDao().findAll();
	}

	public void save(T o) {
		getEntityDao().save(o);
	}

	public void merge(T o) {
		getEntityDao().merge(o);
	}

	public void destory(T o) {
		getEntityDao().destory(o);
	}

	public void destory(PK id) {
		getEntityDao().destory(id);
	}

	public Page<T> findPage(Criteria criteria, int pageNumber, int pageSize) {
		Page<T> page = new Page<T>();
		page.setPageNo(pageNumber);
		page.setPageSize(pageSize);
		return getEntityDao().findPage(page, criteria);
	}
	
	public Page<T> findPage(Criterion[] criterions, int pageNumber, int pageSize) {
		Page<T> page = new Page<T>();
		page.setPageNo(pageNumber);
		page.setPageSize(pageSize);
		return getEntityDao().findPage(page, criterions);
	}

	public Criteria createCriteria(Criterion[] criterions) {
		return getEntityDao().createCriteria(criterions);
	}
	
	public List<T> findByIds(List<PK> idList) {
		return getEntityDao().findByIds(idList);
	}
	
	public List<T> findByIds(PK[] idList) {
		return getEntityDao().findByIds(idList);
	}
	
	public void destoryAll(List<T> pmUsers) {
		
		getEntityDao().destoryAll(pmUsers);
	}
}
